// 01-deploy-fund-me.js
const { network } = require('hardhat')
const {
	DECIMAL,
	INITIAL_ANSWER,
	developmentChains,
} = require('../helper-hardhat-config')

module.exports = async ({ getNamedAccounts, deployments }) => {
	// 只有网络环境为本地环境，才部署 MockV3Aggregator 合约

	if (developmentChains.includes(network.name)) {
		const { deploy } = deployments
		const { firstAccount } = await getNamedAccounts()

		console.log('----------------------------------------------------')
		console.log(`Network: ${network.name}`)
		console.log(`Deploying with account: ${firstAccount}`)
		console.log('Deploying MockV3Aggregator...')

		const MockV3Aggregator = await deploy('MockV3Aggregator', {
			from: firstAccount,
			args: [DECIMAL, INITIAL_ANSWER],
			log: true,
			waitConfirmations: network.config.blockConfirmations || 1,
		})

		console.log(`FundMe deployed at: ${MockV3Aggregator.address}`)
		console.log('----------------------------------------------------')
	} else {
		console.log('enviroment is not local, mock contract deploy is skipped!')
	}
}

module.exports.tags = ['all', 'mock']
